package sample.test.cc.cool.gui.controllers;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;

import sample.test.cc.cool.gui.CreateContainnerWindow;
import BESA.SystemLevel.AdmBESA;

public class AdmController extends Observable {

	private static AdmController instance;
	private CreateContainnerWindow createDialog;

	public static boolean existContainner;

	static {
		existContainner = false;
	}

	private AdmController() {

	}

	public synchronized static AdmController getInstance() {
		if (instance == null)
			instance = new AdmController();
		return instance;
	}

	@Override
	public synchronized void notifyObservers() {
		this.setChanged();
		super.notifyObservers();
	}

	public synchronized void createAdmin(String adminAlias, String ipAddress, int rmiPort,
			String multicastAddress, int multicastPort, int gccPort) {
		try {
			AdmBESA.createInstance(adminAlias, 1.0, ipAddress, rmiPort,
					multicastAddress, multicastPort, gccPort);
			this.notifyObservers();
			existContainner = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public synchronized void addObserver(Observer o) {
		super.addObserver(o);
	}

	public synchronized void showCreateDialog(JFrame parent) {
		this.createDialog = new CreateContainnerWindow(parent);
		this.createDialog.setVisible(true);
	}

}
